package edu.nf.redismqes.service.handler;

import edu.nf.redismqes.mappers.newsMapper;
import edu.nf.redismqes.model.docmentt.NewDoc;
import edu.nf.redismqes.model.entity.New;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @ Author bin
 * @ Create  2025/10/22 上午10:41
 **/
@Service
@Transactional
public class UpdateNewHandler implements NewHandler{
    @Autowired
    private newsMapper newsMapper;

    /**
     * 注入ElasticsearchOperations
     */
    @Autowired
    private ElasticsearchOperations operations;

    @Override
    public String getAction() {
        return "updateNews";
    }

    @Override
    public void handle(New news) {
        newsMapper.update(news);
        NewDoc doc = new NewDoc();
        BeanUtils.copyProperties(news, doc);
        operations.update(doc);
    }
}
